//
//  MessageListViewController.m
//  YTwallet
//
//  Created by ZhangLin on 2019/3/5.
//  Copyright © 2019年 hadrlog. All rights reserved.
//

#import "MessageListViewController.h"
#import "MessageListView.h"
#import "MessageListTableViewCell.h"
#import "MessageDetailViewController.h"
#import "MessageNoneView.h"

#import "MessageModelPack.h"
#import "MessageListDetailModelPack.h"

#import <MJRefresh.h>

@interface MessageListViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>

@property(nonatomic,strong)MessageNoneView *messageNoneView;
@property(nonatomic,strong)MessageListView *mv;
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *messageArray;

@property(nonatomic,strong)UIScrollView *scrollView;
@property(nonatomic,strong)UITableView *profitTableView;
@property(nonatomic,strong)NSMutableArray *profitArray;


// 上拉下拉刷新相关属性

/**
 消息通知当前页
 */
@property(nonatomic,assign) NSInteger messageCurPageNum;
@property(nonatomic,strong) NSString *messageIfHasMore; // 是否有更多数据 0:无 1:有
@property(nonatomic,assign) ETRefreshType messageRefreshType;
@property(nonatomic,assign) BOOL messageIsLoading;


/**
 分润通知当前页
 */
@property(nonatomic,assign) NSInteger profitCurPageNum;
@property(nonatomic,strong) NSString *profitIfHasMore; // 是否有更多数据 0:无 1:有
@property(nonatomic,assign) ETRefreshType profitRefreshType;
@property(nonatomic,assign) BOOL profitIsLoading;


@end

@implementation MessageListViewController

#pragma mark 上拉刷新&下拉刷新
- (void)createMessageHeaderView{
    MJRefreshNormalHeader *headerView = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    // 设置文字
    [headerView setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
    [headerView setTitle:@"释放刷新" forState:MJRefreshStatePulling];
    [headerView setTitle:@"加载中 ..." forState:MJRefreshStateRefreshing];
    // 设置字体
    headerView.stateLabel.font = [UIFont systemFontOfSize:15];
    headerView.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:14];
    // 设置颜色
    headerView.stateLabel.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1];
    headerView.lastUpdatedTimeLabel.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1];
    self.tableView.mj_header = headerView;
    //隐藏上次刷新时间
    headerView.lastUpdatedTimeLabel.hidden = YES;
}

- (void)createMessageFooterView
{
    MJRefreshBackNormalFooter *footerView = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    // 设置文字
    [footerView setTitle:@"上拉刷新" forState:MJRefreshStateIdle];
    [footerView setTitle:@"正在加载更多数据" forState:MJRefreshStateRefreshing];
    [footerView setTitle:@"-已经到底了-" forState:MJRefreshStateNoMoreData];
    // 设置字体
    footerView.stateLabel.font = [UIFont systemFontOfSize:13];
    // 设置颜色
    footerView.stateLabel.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1];
    self.tableView.mj_footer = footerView;
}

- (void)createProfitHeaderView{
    MJRefreshNormalHeader *headerView = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    // 设置文字
    [headerView setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
    [headerView setTitle:@"释放刷新" forState:MJRefreshStatePulling];
    [headerView setTitle:@"加载中 ..." forState:MJRefreshStateRefreshing];
    // 设置字体
    headerView.stateLabel.font = [UIFont systemFontOfSize:15];
    headerView.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:14];
    // 设置颜色
    headerView.stateLabel.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1];
    headerView.lastUpdatedTimeLabel.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1];
    self.profitTableView.mj_header = headerView;
    //隐藏上次刷新时间
    headerView.lastUpdatedTimeLabel.hidden = YES;
}

- (void)createProfitFooterView
{
    MJRefreshBackNormalFooter *footerView = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    // 设置文字
    [footerView setTitle:@"上拉刷新" forState:MJRefreshStateIdle];
    [footerView setTitle:@"正在加载更多数据" forState:MJRefreshStateRefreshing];
    [footerView setTitle:@"-已经到底了-" forState:MJRefreshStateNoMoreData];
    // 设置字体
    footerView.stateLabel.font = [UIFont systemFontOfSize:13];
    // 设置颜色
    footerView.stateLabel.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1];
    self.profitTableView.mj_footer = footerView;
}




- (void)loadNewData{
    
    if (self.mv.messageBtn.selected) {
        if (self.messageIsLoading) {
            return;
        }
        self.messageCurPageNum = 1;
        self.messageRefreshType = ETRefreshDown;
        [self getNetInfoMessag];
    }else if (self.mv.profitBtn.selected)
    {
        if (self.profitIsLoading) {
            return;
        }
        self.profitCurPageNum = 1;
        self.profitRefreshType = ETRefreshDown;
        [self getNetInfoShareprofit];
    }
    
    
}

- (void)loadMoreData{
    
    
    if (self.mv.messageBtn.selected) {
        if (self.messageIsLoading) {
            return;
        }
        self.messageRefreshType = ETRefreshUp;
        self.messageCurPageNum++;
        if ([self.messageIfHasMore isEqualToString:@"0"]) {
            /*
             [self showSuccessResultTips:@"无更多数据" animated:YES forSeconds:SUCCESS_SHOW_TIME_DEF];
             */
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
            return;
        }
        [self getNetInfoMessag];
    }else if (self.mv.profitBtn.selected)
    {
        if (self.profitIsLoading) {
            return;
        }
        self.profitRefreshType = ETRefreshUp;
        self.profitCurPageNum++;
        if ([self.profitIfHasMore isEqualToString:@"0"]) {
            /*
             [self showSuccessResultTips:@"无更多数据" animated:YES forSeconds:SUCCESS_SHOW_TIME_DEF];
             */
            [self.profitTableView.mj_footer endRefreshingWithNoMoreData];
            return;
        }
        [self getNetInfoShareprofit];
    }
    
    
}


-(NSMutableArray *)messageArray
{
    if (_messageArray == nil) {
        _messageArray = [NSMutableArray array];
    }
    return _messageArray;
}



-(NSMutableArray *)profitArray
{
    if (_profitArray == nil) {
        _profitArray = [NSMutableArray array];
    }
    return _profitArray;
}

#pragma mark 初始化
-(void)loadView{
    [super loadView];
    self.mv = [[MessageListView alloc] initWithFrame:self.view.bounds];
    self.view = self.mv;
    

    
}

-(void)createProfitTableView
{
    self.profitTableView = [[UITableView alloc] initWithFrame:CGRectMake(self.view.frame.size.width,  0, self.view.frame.size.width, self.view.frame.size.height - 54 - 64) style:(UITableViewStyleGrouped)];
    self.profitTableView.backgroundColor = [UIColor whiteColor];
    self.profitTableView.delegate = self;
    self.profitTableView.dataSource = self;
    self.profitTableView.separatorStyle = UITableViewCellSelectionStyleNone;
    [self.scrollView addSubview:self.profitTableView];
    [self.profitTableView registerClass:[MessageListTableViewCell class] forCellReuseIdentifier:@"profitCell"];
}
-(void)createScrollView
{
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 54, self.view.frame.size.width, self.view.frame.size.height - 54 - 64)];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.scrollView.backgroundColor = [UIColor whiteColor];
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.bounces = NO;
    self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 0);
    self.scrollView.delegate = self;
    [self.view addSubview:self.scrollView];
}
-(void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,  0, self.view.frame.size.width, self.view.frame.size.height - 54 - 64) style:(UITableViewStyleGrouped)];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    [self.scrollView addSubview:self.tableView];
    [self.tableView registerClass:[MessageListTableViewCell class] forCellReuseIdentifier:@"cell"];
}
//解决增加scrollview禁止左滑返回
-(void)solveConfict
{
    NSArray *gestureArray = self.navigationController.view.gestureRecognizers;
    
    for (UIGestureRecognizer *gestureRecognizer in gestureArray) {
        
        if ([gestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
            
            [self.scrollView.panGestureRecognizer requireGestureRecognizerToFail:gestureRecognizer];
        }
    }
}



-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //禁止tableView下拉上拉刷新影响到左右偏移
    if (![scrollView isEqual:self.scrollView]) {
        return;
    }
    
    float offset = scrollView.contentOffset.x;
    if (offset == 0) {
        self.mv.messageImv.hidden = NO;
        self.mv.profitImv.hidden = YES;
        self.mv.profitBtn.selected = NO;
        self.mv.messageBtn.selected = YES;
        [self.mv.profitBtn setTitleColor:[UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1] forState:(UIControlStateNormal)];
        self.mv.profitBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        
        [self.mv.messageBtn setTitleColor:[UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1] forState:(UIControlStateNormal)];
        self.mv.messageBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    }else if (offset == self.view.frame.size.width)
    {
        self.mv.messageImv.hidden = YES;
        self.mv.profitImv.hidden = NO;
        self.mv.profitBtn.selected = YES;
        self.mv.messageBtn.selected = NO;
        [self.mv.profitBtn setTitleColor:[UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1] forState:(UIControlStateNormal)];
        self.mv.profitBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        
        [self.mv.messageBtn setTitleColor:[UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1] forState:(UIControlStateNormal)];
        self.mv.messageBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.tableView) {
        return self.messageArray.count;
    }else
    {
       return self.profitArray.count;
    }
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.tableView) {
        MessageListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        Record *record = self.messageArray[indexPath.row];
        cell.titleLab.text = record.title;
        cell.detailLab.text = record.content;
        cell.imv.image = [UIImage imageNamed:@"list_ic_message"];
        cell.arrowImv.image = [UIImage imageNamed:@"icon_arrow_right"];
        cell.timeLab.text = record.createTime;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if ([@"0" isEqualToString:record.status]) {
            cell.redPointImv.hidden = NO;
        }else
        {
            cell.redPointImv.hidden = YES;
        }
        return cell;
    }else
    {
        MessageListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"profitCell" forIndexPath:indexPath];
        Record *record = self.profitArray[indexPath.row];
        cell.titleLab.text = record.title;
        cell.detailLab.text = record.content;
        cell.imv.image = [UIImage imageNamed:@"list_ic_message"];
        cell.arrowImv.image = [UIImage imageNamed:@"icon_arrow_right"];
        cell.timeLab.text = record.createTime;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if ([@"0" isEqualToString:record.status]) {
            cell.redPointImv.hidden = NO;
        }else
        {
            cell.redPointImv.hidden = YES;
        }
        return cell;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01f;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (tableView == self.tableView) {
        
        Record *record = self.messageArray[indexPath.row];
        [self getMessageListDetailWithmsgId:record.msgId];
        
    }else
    {
        Record *record = self.profitArray[indexPath.row];
        [self getMessageListDetailWithmsgId:record.msgId];
    }
    
}
//获取详情
-(void)getMessageListDetailWithmsgId:(NSString *)messageId
{
    MessageListDetailRequest *request = [[MessageListDetailRequest alloc] init];
    request.msgId = messageId;
    NSDictionary *dic = [request mj_JSONObject];
    NSString *url = [[ServerAddressModel shareInstance] fullTAnd0AddrWithParameter:@"/epay_apps/push/findMsgDetail"];
    [[ETONEHttpClient sharedInstance] doHTTPSPOST:url Parameters:dic HttpBody:nil SuccessHandler:^(id responseObject) {
        
        NSDictionary *dic = [responseObject mj_JSONObject];
        NSString *code = dic[@"code"];
        if ([@"0000" isEqualToString:code]) {
            [self dealMessageListDetailWithresponse:responseObject messageId:messageId];
        }
    } FailedHandler:^(NSError *error) {
        
    }];
}

-(void)dealMessageListDetailWithresponse:(id)responseObject messageId:(NSString *)messageId
{
    
    
    if ([messageId isEqualToString:[AppTools shareInstance].msgInfo.ID]) {
        [AppTools shareInstance].msgInfo.status = @"1";
    }
    
    MessageListDetailResponse *messageListDetailResponse = [MessageListDetailResponse mj_objectWithKeyValues:responseObject];
    MessageListDetailResponseData *detailRecord = messageListDetailResponse.response;
    MessageDetailViewController *messageVC = [[MessageDetailViewController alloc] init];
    messageVC.titleValueStr = detailRecord.title;
    messageVC.timeValueStr = detailRecord.createTime;
    messageVC.detailValueStr = detailRecord.content;
    [self.navigationController pushViewController:messageVC animated:YES];
}



//点击消息通知
-(void)messageBtnAction
{
    self.mv.messageImv.hidden = NO;
    self.mv.profitImv.hidden = YES;
    [self.mv.profitBtn setTitleColor:[UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1] forState:(UIControlStateNormal)];
    self.mv.profitBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    
    [self.mv.messageBtn setTitleColor:[UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1] forState:(UIControlStateNormal)];
    self.mv.messageBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    
    //显示消息列表
    self.scrollView.contentOffset = CGPointMake(0, 0);
    
    
}
//点击分润通知
-(void)profitBtnAction
{
    self.mv.messageImv.hidden = YES;
    self.mv.profitImv.hidden = NO;
    [self.mv.profitBtn setTitleColor:[UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1] forState:(UIControlStateNormal)];
    self.mv.profitBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    
    [self.mv.messageBtn setTitleColor:[UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1] forState:(UIControlStateNormal)];
    self.mv.messageBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    
    //显示分润通知
    self.scrollView.contentOffset = CGPointMake(self.view.frame.size.width, 0);
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"消息列表";
    self.view.backgroundColor = ETColorWithRGB(242, 244, 246);
    
    self.mv.profitImv.hidden = YES;
    self.mv.messageBtn.selected = YES;
    
    
    
    [self.mv.messageBtn addTarget:self action:@selector(messageBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.mv.profitBtn addTarget:self action:@selector(profitBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    //创建scrollView
    [self createScrollView];
    //创建tableView(消息通知)
    [self createTableView];
    //创建tableView(分润通知)
    [self createProfitTableView];
    
    
    // 上拉下拉刷新相关设置
    self.messageCurPageNum = 1;
    self.messageIfHasMore = @"1";
    self.profitCurPageNum = 1;
    self.profitIfHasMore = @"1";
    [self createMessageHeaderView];
    [self createMessageFooterView];
    
    [self createProfitHeaderView];
    [self createProfitFooterView];
    
    
    
    //解决手势冲突
    [self solveConfict];
    
    //后端请求数据列表
    
    /*
    //创建任务组
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_enter(group);
    dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    
        dispatch_group_leave(group);
        
    });
    
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        //界面刷新
        
    });
     */
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.messageArray removeAllObjects];
    [self.profitArray removeAllObjects];
    
    [self getNetInfoMessag];           //消息通知
    [self getNetInfoShareprofit];      //分润通知
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

-(void)getNetInfoMessag
{
    MessageRequest *request = [[MessageRequest alloc] init];
    request.pageNum = [NSString stringWithFormat:@"%ld",(long)self.messageCurPageNum];
    request.pageSize = PAGESIZE;
    request.msgRemark = @"1";
    NSDictionary *dic = [request mj_JSONObject];
    NSString *url = [[ServerAddressModel shareInstance] fullTAnd0AddrWithParameter:@"/epay_apps/push/getPushMsgList"];
    [[ETONEHttpClient sharedInstance] doHTTPSPOST:url Parameters:dic HttpBody:nil SuccessHandler:^(id responseObject) {
        
        self.messageIsLoading = NO;
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        
        NSDictionary *dic = [responseObject mj_JSONObject];
        NSString *code = dic[@"code"];
        if ([@"0000" isEqualToString:code]) {
            [self dealMessageResponse:responseObject];
        }else{
            //移除tableView  展示无消息
            self.messageNoneView = [[MessageNoneView alloc] initWithFrame:(CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 54))];
            [self.scrollView addSubview:self.messageNoneView];
            
        }
        
        

    } FailedHandler:^(NSError *error) {
        
        self.messageIsLoading = NO;
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        
        //移除tableView  展示无消息
        self.messageNoneView = [[MessageNoneView alloc] initWithFrame:(CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 54))];
        [self.scrollView addSubview:self.messageNoneView];
        
    }];
}

-(void)getNetInfoShareprofit
{
    MessageRequest *request = [[MessageRequest alloc] init];
    request.pageNum = [NSString stringWithFormat:@"%ld",(long)self.profitCurPageNum];
    request.pageSize = PAGESIZE;
    request.msgRemark = @"3";
    NSDictionary *dic = [request mj_JSONObject];
    NSString *url = [[ServerAddressModel shareInstance] fullTAnd0AddrWithParameter:@"/epay_apps/push/getPushMsgList"];
    [[ETONEHttpClient sharedInstance] doHTTPSPOSTNOTips:url Parameters:dic HttpBody:nil SuccessHandler:^(id responseObject) {

        [self.profitTableView.mj_header endRefreshing];
        [self.profitTableView.mj_footer endRefreshing];
        
        NSDictionary *dic = [responseObject mj_JSONObject];
        NSString *code = dic[@"code"];
        if ([@"0000" isEqualToString:code]) {
            
            [self dealshareProfitResponse:responseObject];
            
        }else
        {
            //移除tableView  展示无消息
            self.messageNoneView = [[MessageNoneView alloc] initWithFrame:(CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height - 54))];
            [self.scrollView addSubview:self.messageNoneView];
        }
        
        
        
    } FailedHandler:^(NSError *error) {
        
        [self.profitTableView.mj_header endRefreshing];
        [self.profitTableView.mj_footer endRefreshing];
        
        
        //移除tableView  展示无消息
        self.messageNoneView = [[MessageNoneView alloc] initWithFrame:(CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height - 54))];
        [self.scrollView addSubview:self.messageNoneView];
        
    }];
}
//消息通知
-(void)dealMessageResponse:(id)responseObject
{
    dispatch_async(dispatch_get_main_queue(), ^{
        MessageResponse *messageResponse = [MessageResponse mj_objectWithKeyValues:responseObject];
        NSInteger i = messageResponse.response.recordList.count;
        
        if (i < 10) {
            self.messageIfHasMore = @"0";
        }else
        {
            self.messageIfHasMore = @"1";
        }
        
        
        if (i == 0) {
            //移除tableView  展示无消息
            self.messageNoneView = [[MessageNoneView alloc] initWithFrame:(CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 54))];
            [self.scrollView addSubview:self.messageNoneView];
        }else
        {
            
            if (self.messageRefreshType == ETRefreshUp) {
                
                for (Record *record in messageResponse.response.recordList) {
                    [self.messageArray addObject:record];
                }
                
            }else if (self.messageRefreshType == ETRefreshDown)
            {
                [self.messageArray removeAllObjects];
                for (Record *record in messageResponse.response.recordList) {
                    [self.messageArray addObject:record];
                }
            }
            
            
            
            [self.tableView reloadData];
        }
        
    });
}
//分润通知
-(void)dealshareProfitResponse:(id)responseObject
{
    dispatch_async(dispatch_get_main_queue(), ^{
        MessageResponse *messageResponse = [MessageResponse mj_objectWithKeyValues:responseObject];
        NSInteger i = messageResponse.response.recordList.count;
        if (i < 10) {
            self.profitIfHasMore = @"0";
        }else
        {
            self.profitIfHasMore = @"1";
        }
        
        
        if (i == 0) {
            //移除tableView  展示无消息
            self.messageNoneView = [[MessageNoneView alloc] initWithFrame:(CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height - 54))];
            [self.scrollView addSubview:self.messageNoneView];
        }else
        {
            
            if (self.profitRefreshType == ETRefreshUp) {
                
                for (Record *record in messageResponse.response.recordList) {
                    [self.profitArray addObject:record];
                }
                
            }else if (self.profitRefreshType == ETRefreshDown)
            {
                [self.profitArray removeAllObjects];
                for (Record *record in messageResponse.response.recordList) {
                    [self.profitArray addObject:record];
                }
            }
            
            
            
            [self.profitTableView reloadData];
        }
    });
}


//设置tableView的分割线的显示
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:(UIEdgeInsetsMake(0, 60, 0, 0))];
        [self.profitTableView setSeparatorInset:(UIEdgeInsetsMake(0, 60, 0, 0))];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 60, 0, 0)];
        [self.profitTableView setLayoutMargins:UIEdgeInsetsMake(0, 60, 0, 0)];
    }
}




@end
